package com.woniuxy.utils;

import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;

//散列算法工具
public class MD5Util {

	// 随机生成6位字符salt
	public static String generateSalt() {
		SecureRandomNumberGenerator secureRandom = new SecureRandomNumberGenerator();
		return secureRandom.nextBytes(3).toHex();
	}

	// 获取加密后的密码
	public static String encryptPassword(String password, String salt) {
		SimpleHash hash = new SimpleHash("MD5", password, salt, 2);
		return hash.toString();
	}
}
